package Offer2017;

/**
 * 递增数组中和为s的两个数字
 * Created by 雷文康 on 2018/1/6.
 */
public class Test41 {
    public static void main(String[] args) {
        int array[]={1,2,4,6,8,9,12};
        findNumOfSum(array,13);
    }

    public static void findNumOfSum(int[] array, int sum){
        if (array == null || array.length < 2){
            return;
        }
        int start = 0;
        int end = array.length - 1;
        while (start < end){
            if (array[start] + array[end] == sum){
                System.out.println("找到结果");
                System.out.print(array[start]);
                System.out.print(" ");
                System.out.print(array[end]);
                start++;
                end--;
            } else if (array[start] + array[end] < sum){
                start++;
            } else {
                end--;
            }
        }
    }
}
